package com.itheima.admin.service.impl;

import com.itheima.admin.mapper.ClassTableMapper;
import com.itheima.admin.pojo.ClassTable;
import com.itheima.admin.pojo.WeekClass;
import com.itheima.admin.service.ClassTableService;
import com.itheima.admin.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ClassTableServiceImpl implements ClassTableService {
    @Autowired
    private ClassTableMapper classTableMapper;
    @Override
    public Result selectAllClass() {
        List<ClassTable> classTables = new ArrayList<>();
        for(int i=1;i<=6;i++){
            ClassTable classTable = new ClassTable();
            classTable.setClassNum(i);
            List<WeekClass> weekClasses = classTableMapper.selectAllClass(i);
            classTable.setWeekClasses(weekClasses);
            classTables.add(classTable);
        }
        return Result.success(200,"查询到所有课程",classTables) ;
    }

    @Override
    public Result insertClass(ClassTable classTable) {
        Integer integer = classTableMapper.insertClass(classTable);
        if(integer == 0){
            return Result.error("添加课程失败");
        }
        return Result.success(200,"添加课程成功");
    }

    @Override
    public Result deleteClass(ClassTable classTable) {
        Integer integer = classTableMapper.deleteClass(classTable);
        if(integer == 0){
            return Result.error("删除课程失败");
        }
        return Result.success(200,"删除课程成功");
    }
}
